home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 3
/
Gold Medal Software - Volume 3 (Gold Medal) (1994).iso
/
windows
/
prinfon
/
ajcprt.arj
/
AJCPRNTW.DOC
next >
Wrap
Text File
|
1994-01-16
|
8KB
|
263 lines
AJCPrntW - Printer Unit for Windows
This unit was written using Borland International's Borland
Pascal v7.0, and the Object Windows Library (OWL) provided with
that product.
I have not copyrighted this program, and donate it to the public
domain. All portions of this program may be used, modified,
and/or distributed, in whole or in part.
I wrote this unit to provide myself with some reusible functions
that would help me out in preparing printed hard copy from an
OWL program. I am just a "hobby" programmer, having written
nothing for anyone but myself. Therefore, this unit may not be
comprehensive, or even particularly robust. However, it has met
my own needs, and it may actually be usefull to someone
else--besides, it's free! I am open to suggestions, comments,
or enhancements (although, I can't promise quick turn around
because I have a real job, plus I teach, plus I have a
family--then I code for fun--in that order <grin>).
This unit provides two objects that are descended from the
printing objects provided by OWL.
TAJCPrinter
TAJCPrinter is descended from TPrinter. It provides a single
additional method, SetPageOrientation.
SetPageOrientation
SetPageOrientation takes a single parameter, Orientation.
Orientation is an Integer parameter that indicates whether the
orientation should be portrait or landscape. You can use the
constants dmOrient_Portrait and dmOrient_Landscape, which are
provided by WinTypes.
SetPageOrientation returns an integer value which indicates the
success or failure of the call. -1 indicates failure, while 0
indicates success.
As far as I have determined, SetPageOrientation can be called
anytime after the object has been initialized with the inherited
Init method.
As currently coded, it only works with printer drivers that
support ExtDeviceMode, and it doesn't bother to check for the
device's capabilities first.
TAJCPrinOut
TAJCPrintOut is descended from TPrintOut. It provides five
additional data attributes, overrides three methods, and
provides ten new methodes.
VUnitsPerInch: Integer
VUnitsPerInch contains the number of Logical Device Units per
Logical Inch in the vertical direction on the device.
HUnitsPerInch: Integer
HUnitsPerInch contains the number of Logical Device Units per
Logical Inch in the horizontal direction on the device.
LMarginUnits: Integer
The number of Logical Device Units in the unprintable left
margin of the physical device. (This value can also be assumed
to represent the size of the unprintable right margin.
RMarginUnits: Integer
The number of Logical Device Units in the unprintable top margin
of the physical device. (This value can also be assumed to
represent the size of the unprintable bottom margin.
OriginalAlignmentOptions: Word
This word variable is a holder for the original text alignment
options for the Device Context. It is used to clean up the use
of the Device Context by putting it back the way it was. It is
set by JustifyLeft, JustifyCenter, and JustifyRight. If its
value is zero, then none of the three Justify... methods have
been called yet.
Init(ATitle: PChar);
Init calls the inherited Init, and initializes
OriginalAlignmentOptions to zero.
Done
If OriginalAlignmentOptions is non-zero, then SetTextAlign is
called to return the Text Alignment settings to their original
state.
Next, the inherited Done is called.
SetPrintParams(ADC: HDC; ASize: TPoint);
After calling the inherited SetPrintParams, this SetPrintParams
initializes the five data attributes described above with their
working values.
VLogPos(Pos: Integer): Integer;
VLogPos takes an integer value that represents an X coordinate
relative to the physical edge of the paper. VLogPos returns an
X coordinate that takes into account (that is, adjusts for) the
unprintable part of the paper.
If Pos is negative, then it is considered to be relative to the
right edge of the paper, otherwise it is assumed to be relative
to the left edge of the paper.
For example, if Size.X is 40, and the size of the unprintable
side margins are 3, then VLogPos(10) returns 7, and VLogPos(-10)
returns 33.
HLogPos(Pos: Integer): Integer;
HLogPos takes an integer value that represents a Y coordinate
relative to the physical edge of the paper. HLogPos returns a Y
coordinate that takes into account (that is, adjusts for) the
unprintable part of the paper.
If Pos is negative, then it is considered to be relative to the
bottom edge of the paper, otherwise itis assumed to be relative
to the top edge of the paper.
For example, if Size.Y is 40, and the size of the unprintable
top/bottom margins are 3, then HLogPos(10) returns 6, and
HLogPos(-10) returns 33.
VInches(Inches: Real): Integer;
VInches takes a Real value that represents a number of inches
(such as 1.5) and returns an integer value that represents the
number of Logical Units in the virtical direction that would
correspond to that number of inches.
HInches(Inches: Real): Integer;
HInches takes a Real value that represents a number of inches
(such as 1.5) and returns an integer value that represents the
number of Logical Units in the horizontal direction that would
correspond to that number of inches.
(Notes on the usage of VLogPos, HLogPos, VInches, and HInches)
Here's an example of how I've been using these methods:
TextOut(DC, VLogPos(VInches(1.0)), HLogPos(HInches(1.0)), ....)
That will print text starting 1 inch down from the top edge of
the paper, and 1 inch to the right of the left edge of the paper.
Points(APoints: Integer): Integer;
Points a text height, APoints, expressed in Points, and returns
an integer value representing the number of Logical Units, in
the vertical direction, that correspond to that number of points.
PrintHeader(Mode, Page: Word): Integer;
This is an abstract unit that should be overridden. Mode should
be passed one of the constant values pm_Size or pm_Print. Page
should represent the page number being printed. PrintHeader
should return an Integer value that represents the virtical size
of the header in Logical Units.
If Mode is pm_Size, then PrintHeader should return the header
size and nothing else. If Mode is pm_Print, then PrintHeader
should print the header AND return the size of the header.
PrintFooter(Mode, Page: Word): Integer;
This is an abstract unit that should be overridden. Mode should
be passed one of the constant values pm_Size of pm_Print. Page
should represent the page number being printed. PrintFooter
should return an Integer value that represents the virtical size
of the footer in Logical Units.
If Mode is pm_Size, then PrintFooter should return the footer
size and nothing else. If Mode is pm_Print, then PrintFooter
should print the footer AND return the size of the footer.
JustifyLeft;
JustifyLeft changes the text alignment options for the Device
Context so that text printed with TextOut and ExtTextOut Left
Justified. This option remains in effect until JustifyCenter or
JustifyRight are called. If this is the first call to one of
the Justify... methods, then the original alignment options are
stored in OriginalAlignmentOptions so that they can be reset by
the Done method.
JustifyCenter;
JustifyCenter changes the text alignment options for the Device
Context so that text printed with TextOut and ExtTextOut
Centered. This option remains in effect until JustifyLeft or
JustifyRight are called. If this is the first call to one of
the Justify... methods, then the original alignment options are
stored in OriginalAlignmentOptions so that they can be reset by
the Done method.
JustifyRight;
JustifyRight changes the text alignment options for the Device
Context so that text printed with TextOut and ExtTextOut Right
Justified. This option remains in effect until Justify Left or
JustifyCenter are called. If this is the first call to one of
the Justify... methods, then the original alignment options are
stored in OriginalAlignmentOptions so that they can be reset by
the Done method.